package net.hn.hnms.biz.plan.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.plan.request.DimShiftReq;
import net.hn.hnms.biz.plan.service.IDimShiftService;
import net.hn.hnms.biz.plan.vo.DimShiftVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班次信息
 *
 * @author zhaoyang
 * @date 2022-08-01
 */

@Api(value = "班次信息模块", tags = {"班次信息"})
@RestController
@RequestMapping("/shift")
public class DimShiftController extends BaseController {


    @Autowired
    private IDimShiftService dimShiftService;

    /**
     * 新增班次信息
     */
    @ApiOperation("新增班次信息")
    @SaCheckPermission("plan:shift:add")
    @PostMapping("/add")
    @Log(title = "新增班次信息", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody DimShiftReq dimShift) {

        return toAjax(dimShiftService.insert(dimShift));
    }

    /**
     * 删除班次信息
     */
    @ApiOperation("删除班次信息")
    @SaCheckPermission("plan:shift:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除班次信息", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        dimShiftService.deleteBatch(idList);
        return R.ok();
    }

    /**
     * 修改班次信息
     */
    @ApiOperation("修改班次信息")
    @SaCheckPermission("plan:shift:update")
    @PutMapping("/update")
    @Log(title = "修改班次信息", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody DimShiftReq dimShift) {
        dimShiftService.updateById(dimShift);
        return R.ok();
    }

    /**
     * 启用/禁用
     */
    @ApiOperation("启用/禁用")
    @SaCheckPermission("plan:shift:status:change")
    @PutMapping("/status/change/{id}/{status}")
    @Log(title = "班次启用/禁用", businessType = BusinessType.GRANT)
    public R<Void> changeStatus(@PathVariable("id") String id, @PathVariable("status") Integer status) {
        dimShiftService.changeStatus(id, status);
        return R.ok();
    }

    /**
     * 获取班次信息列表
     */
    @ApiOperation("获取班次信息分页列表")
//    @SaCheckPermission("plan:shift:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<DimShiftVO>> page(DimShiftReq dimShift, PageQuery pageQuery) {
        return R.ok(dimShiftService.selectPageList(dimShift, pageQuery));
    }

    /**
     * 获取班次信息列表
     */
    @ApiOperation("获取班次信息列表")
//    @SaCheckPermission("plan:shift:list")
    @GetMapping("/list")
    @AutoSetMineCode
    public R<List<DimShiftVO>> list(DimShiftReq dimShift) {
        return R.ok(dimShiftService.selectList(dimShift));
    }

    /**
     * 获取班次信息详情
     */
    @ApiOperation("获取班次信息详情")
//    @SaCheckPermission("plan:shift:detail")
    @GetMapping("/{id}")
    public R<DimShiftVO> detail(@PathVariable("id") String id) {
        return R.ok(dimShiftService.selectDetailById(id));
    }


}
